#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct Stu
{
	char name[20];
	int age;
};
void print_int(int arr[], int sz)
{
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%d ", arr[i]);
	}
	printf("\n");
}

void print_double(double arr[], int sz)
{
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%lf ", arr[i]);
	}
	printf("\n");
}

void print_char(char arr[], int sz)
{
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%c ", arr[i]);
	}
	printf("\n");
}

void print_chars(char arr[][10], int sz)
{
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%s ", arr[i]);
	}
	printf("\n");
}

void print_stu_name(struct Stu arr[], int sz)
{
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%s ", arr[i].name);
	}
	printf("\n");
}
void print_stu_age(struct Stu arr[], int sz)
{
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%d ", arr[i].age);
	}
	printf("\n");
}

int cam_int(const* p1, const* p2)
{
	return *(int*)p1 - *(int*)p2;
}
int cam_double(const* p1, const* p2)
{
	return *(double*)p1 - *(double*)p2;
}
int cam_char(const* p1, const* p2)
{
	return *(char*)p1 - *(char*)p2;
}
int cam_chars(const* p1, const* p2)
{
	return *(char*)p1 - *(char*)p2;
}
int cam_stu_name(const void* p1, const void* p2)
{
	return strcmp(((struct Stu*)p1)->name, ((struct Stu*)p2)->name);
}
int cam_stu_age(const void* p1, const void* p2)
{
	return ((struct Stu*)p1)->age - ((struct Stu*)p2)->age;
}
void text1()
{
	int arr[] = { 2,3,4,8,1,9,5,7,6 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	qsort(arr, sz, sizeof(arr[0]), cam_int);
	print_int(arr, sz);
}
void text2()
{
	double arr[] = { 1.2,3.2,2.7,6.4,2.5 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	qsort(arr, sz, sizeof(arr[0]), cam_double);
	print_double(arr, sz);
}
void text3()
{
	char arr[] = { 'a','c','b','u','f' };
	int sz = sizeof(arr) / sizeof(arr[0]);
	qsort(arr, sz, sizeof(arr[0]), cam_char);
	print_char(arr, sz);
}
void text4()
{
	char arr[][10] = {"ab","ef","cd","xy"};
	int sz = sizeof(arr) / sizeof(arr[0]);
	qsort(arr, sz, sizeof(arr[0]), cam_chars);
	print_chars(arr, sz);
}

void text5()
{
	struct Stu arr[3] = { {"zhangsan", 20},{"lisi", 35},{"wangwu", 18} };
	int sz = sizeof(arr) / sizeof(arr[0]);
	qsort(arr, sz, sizeof(arr[0]), cam_stu_name);
	print_stu_name(arr, sz);
	
}
void text6()
{
	struct Stu arr[3] = { {"zhangsan", 20},{"lisi", 35},{"wangwu", 18} };
	int sz = sizeof(arr) / sizeof(arr[0]);
	qsort(arr, sz, sizeof(arr[0]), cam_stu_age);
	print_stu_age(arr, sz);

}
int main()
{
	text1();
	text2();
	text3();
	text4();
	text5();
	text6();
	return 0;
}